'use strict';

const { Controller } = require('egg');
const {success} = require('../extend/api')
class UserController extends Controller {
  constructor(ctx){ 
    super(ctx);
    this.createRule = {
      username:{
        type:'string',
        min:6,
        max:18,
        formate:/^[\u4e00-\u9fa5A-Za-z0-9_]{6,20}$/
      },
      password:{
        type:'password',
        min:6,
        max:18,
        formate:/^[A-Za-z0-9_]{6,20}$/
      }
    }
  }

  async signup() {
    const { ctx,service } = this;
    const body = ctx.request.body
    const res = await service.admin.signup(body)
    ctx.body = res
    }

  async signin(){
    const { ctx,service } = this;
    const data = ctx.request.body
    ctx.validate(this.createRule,data)
    const res = await service.admin.signin(data) 
    success({
      ctx,res
    })
  }

  async signout(){
    const { ctx,service } = this;
    const res = await service.admin.signout()
    success({ctx,res})
  }

  async getUserData(){
    const { ctx,service } = this;
    const res = await service.admin.getUserData()
    success({ctx,res})
  }

  async silenceUser(){
    const { ctx,service } = this;
    const body = ctx.request.body
    const res = await service.admin.silenceUser(body)
    success({ctx,res})
  }
  
  async bannedUser(){
    const { ctx,service } = this;
    const body = ctx.request.body
    const res = await service.admin.bannedUser(body)
    success({ctx,res})
  }

  async changePassWord(){
    const { ctx,service } = this;
    const body = ctx.request.body
    const res = await service.admin.changePassWord(body)
    success({ctx,res})
  }

}

module.exports = UserController;
